package com.itheima.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

/**
 * @author 何景航
 * @date 2025/11/1 7:45
 */
public class JwtUtils {

    private static final String SECERT_KEY = "aHNpc2hhbmRzb21l";
    private static final long EXPIRATION_TIME = 12*60*60*1000;

    public static String generateToken(Map<String,Object> claims){
        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,SECERT_KEY)
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
                .compact();
    }


    public static Claims parserToken(String token) throws Exception{
        return Jwts.parser()
                .setSigningKey(SECERT_KEY)
                .parseClaimsJws(token)
                .getBody();
    }
}
